package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceFilesInfoEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;
import com.yuexunit.persist.annotation.Transactional;

/**
*@version 创建时间：2017年3月13日 下午3:39:22
*@author wenwenlong
*类说明
*/

@Implements(FinanceFilesInfoService.class)
public class FinanceFilesInfoServiceImpl implements FinanceFilesInfoService {

	@Override
	@Transactional
	public Long createFinanceFilesInfo(FinanceFilesInfoEntity entity) {
		PersistUtil.insert(entity);
		return entity.getFilesInfoId();
	}

	@Override
	@Transactional
	public void updateFinanceFilesInfo(FinanceFilesInfoEntity entity) {
		PersistUtil.update(entity);
	}

	@Override
	public List<FinanceFilesInfoEntity> inquireFinanceFilesInfoList(Long financeId, Long financeContractId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceFilesInfoEntity.class);
		criteria.add(Restrictions.eq("financeId", financeId));
		if (financeContractId == null) {
			criteria.add(Restrictions.isNull("financeContractId"));
		} else {
			criteria.add(Restrictions.eq("financeContractId", financeContractId));
		}
		return PersistUtil.get(criteria);
	}
	
	@Override
	public List<FinanceFilesInfoEntity> inquireFinanceFilesInfoListByPickupId(Long pickupId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceFilesInfoEntity.class);
		criteria.add(Restrictions.eq("pickupId", pickupId));
		return PersistUtil.get(criteria);
	}

	@Override
	public FinanceFilesInfoEntity inquireFinanceFilesInfo(Long filesInfoId) {
		return PersistUtil.get(FinanceFilesInfoEntity.class, filesInfoId);
	}
}
